<!DOCTYPE html>
<html>
<head>
    <title>创建文档</title>

    $css()$js()
    <script type="text/javascript" src="/public/assets/editor/kindeditor-all-min.js"></script>
    <script type="text/javascript" src="/public/assets/editor/plugins/code/prettify.js"></script>

</head>
<body>
    <form method="post" id="form1" action="" enctype="application/x-www-form-urlencoded">

        <div class="tabarea">
            <div class="tab_mini">
                <a href="javascript:;" class="current">添加文档</a>
            </div>
            <div class="area">

                <div class="archive_edit form">
                    <div class="title" style="margin-top: 0">
                        <span class="icon icon1"></span>基本&nbsp;&nbsp;
                        <span style="font-weight:normal">(<span class="star">*</span>为必填项,其他选填)</span>
                    </div>
                    <input type="hidden" field="Id" value="0" />
                    <dl>
                        <dt><span class="star">*</span>栏目：</dt>
                        <dd>
                            <select field="CategoryId" class="tb_normal ui-box" required="true" summary="{required:'请选择栏目!'}">
                                <option>一请选择栏目一</option>
                                ${nodes}
                            </select>
                        </dd>
                    </dl>

                    <dl>
                        <dt><span class="star">*</span>标题：</dt>
                        <dd>
                            <input class="ui-box ui-validate ruler" required="true" length="[1,100]" summary="{required:'标题不能为空!',length:'标题长度1-100字!'}" type="text" field="Title" id="title" style="width: 500px" />

                        </dd>
                    </dl>

                    <dl>
                        <dt>子标题：</dt>
                        <dd>
                            <input class="tb_normal ui-box ui-validate" style="width: 340px;" length="[0,100]" summary="{length:' 子标题长度1-100字!'}" type="text" field="SmallTitle" />
                        </dd>
                    </dl>

                    <dl>
                        <dt>别名：</dt>
                        <dd>
                            <input style="width: 340px;" tipin="alias_tipin" type="text" id="alias" field="Alias" class="tb_normal ui-box ui-validate" summary="{error:'别名为50位以下的数字,字母,连接符(-),下划线的组合'}" /><span class="ui-button w80 middle-button">
                                <span class=" button-inner">
                                    <span class="button-txt">自动填写</span>
                                    <a href="javascript:;"></a>
                                </span>
                            </span>&nbsp;&nbsp;

                            <span id="alias_tipin"></span>
                            <br/>
                            <span style="padding-left:41px;line-height:30px">注：用于生成更又好的文档地址，比如：http://abc.com/about/contact.html。</span>
                        </dd>

                    </dl>

                    <dl>
                        <dt>重定向：</dt>
                        <dd>
                            <input type="radio" class="radio" field="IsRedirect" name="IsRedirect" id="IsRedirect1" value="0" checked="checked" /><label for="IsRedirect1">否</label>
                            <input type="radio" class="radio" field="IsRedirect" name="IsRedirect" id="IsRedirect2" value="1" /><label for="IsRedirect1">是</label>

                            <span id="redirectPanel" class="hidden" style="padding-left:20px">
                                网址(URL)：<input class="tb_normal ui-box ui-validate" length="[0,150]" name="location" field="Location" />
                            </span>
                            <br /> <span class="desc" style="padding-left:60px">提示：重定向可以将文档页面跳转到指定的网址。</span>
                        </dd>
                    </dl>


                    <dl>
                        <dt>来源：</dt>
                        <dd>
                            <input class="tb_normal ui-box ui-validate" length="[0,10]" type="text" field="Source" style="width: 100px" />
                            &nbsp;&nbsp;&nbsp;<strong>设置：</strong>
                            <input type="checkbox" style="border: none" field="IsVisible" id="ck_visible" title="取消勾选将不会显示此文档"/><label for="ck_visible">显示</label>
                            &nbsp;<input type="checkbox" style="border: none" field="IsSpecial" title="以特殊的形式显示" id="ck_special" /><label for="ck_special">推荐</label>
                            &nbsp;<input type="checkbox" style="border: none" field="IsSystem" title="用于系统使用的文档(系统页面不会在搜索和列表中出现)" id="ck_system" /><label for="ck_system">系统</label>
                            &nbsp;<input type="checkbox" style="border: none" field="AsPage" title="单页，会以单页的URL地址显示" id="ck_single" /><label for="ck_single">页面</label>
                        </dd>
                    </dl>


                    <dl>
                        <dt>定时发布：</dt>
                        <dd>
                            <input type="radio" class="radio" field="IsSchedule" name="IsSchedule" id="IsSchedule1" value="0" checked="checked" /><label for="IsSchedule1">否</label>
                            <input type="radio" class="radio" field="IsSchedule" name="IsSchedule" id="IsSchedule2" value="1" /><label for="IsSchedule1">是</label>

                            <span id="schedulePanel" class="hidden" style="padding-left:20px">
                                时间：<input class="schedual-time tb_normal ui-box ui-validate" name="scheduleTime" field="ScheduleTime" />
                            </span>
                            <br /> <span class="desc" style="padding-left:60px">提示：定时发布可以将文档页面在指定时间发布。</span>
                        </dd>
                    </dl>


                    <!-- 960的宽度为标准,一般内容宽度为600左右 -->

                    <div class="title"><span class="icon icon1"></span>内容编辑：</div>
                    <div id="contentinfo" style="width: 620px;margin:0 auto 0 40px">
                        <span>建议：使用一键排版功能可以快速生成有格式的内容。<br /><br /></span>
                        <textarea id="editor" field="Content" style="overflow: hidden; width: 620px; height: 400px;"></textarea>
                    </div>


                    <div class="title"><span class="icon icon1"></span>显示</div>
                

                    <div class="clearfix"></div>
                    <dl>
                        <dt>摘要：&nbsp;</dt>
                        <dd>
                            <textarea class="ui-validate ui-box" length="[0,500]" field="Outline" rows="3" cols="5" style="width: 500px; font-size: 12px;"></textarea>
                        </dd>
                    </dl>
                    <div class="clearfix"></div>
                    <dl>
                        <dt>缩略图：</dt>
                        <dd style="position: relative;height: 120px;padding-left:200px" class="flex flex-column gap">

                            <div class="g-suited-img g-suited-img-65" style="position:absolute;left:0px;width:180px;height:120px;border:solid 1px #aaa;padding:1px !important;">
                                <img id="thumbnail_img" alt="" src=""/>
                            </div>
                            
                            <input class="tb_normal ui-box ui-validate" length="[0,150]" type="hidden" field="Thumbnail" id="thumbnail" size="100" />
                            <span class="ui-button middle-button" style="width:120px" id="upload_thumbnail">
                                <span class=" button-inner">
                                    <span class="button-txt">上传图片</span>
                                    <a href="javascript:;"></a>
                                </span>
                            </span>

                            <br/>
                            <span class="ui-button middle-button" style="width:120px" id="pick_image">
                                <span class=" button-inner">
                                    <span class="button-txt">浏览图片</span>
                                    <a href="javascript:;"></a>
                                </span>
                            </span>
                            </br/>

                            <span class="ui-button middle-button" style="width:120px" id="ipt_getImg" onclick="getImg();">
                                <span class=" button-inner">
                                    <span class="button-txt">获取编辑器图片</span>
                                    <a href="javascript:;"></a>
                                </span>
                            </span>&nbsp;
                            <select class="ui-box" id="upimg" name="upimg" style="display: none">
                                <option value="">选择图片</option>
                            </select>&nbsp;
                        </dd>
                    </dl>

                    <div class="clearfix"></div>



                    <dl>
                        <dt>视图：</dt>
                        <dd>
                            <select field="TemplatePath" id="TemplatePath" class="tb_normal ui-box">
                                <option value="">一默认一</option>
                                ${tpls}
                            </select>&nbsp;&nbsp;设置文档的显示模板，通常使用“默认”即可。
                        </dd>
                    </dl>

                    <dl>
                        <dt>Tags：</dt>
                        <dd>
                            <textarea class="tb_normal ui-box ui-validate" length="[0,100]" type="text" field="Tags" rows="3" style="width:500px"></textarea>
                            <br />
                            <span style="padding-left:41px;line-height:30px"><input id="ck_auto_tag" type="checkbox" style="border: none" field="auto_tag" title="自动链接Tags" checked="checked" /><label for="ck_auto_tag">自动链接(自动生成tags链接，有利于seo)</label></span>
                        </dd>
                    </dl>


                    <div id="extend_field" class="${extend_cls}">
                        <div class="title"><span class="icon icon1"></span>扩展属性：</div>
                        <div class="extinfo">
                            ${extendFieldsHtml}
                        </div>
                    </div>

                    <div class="submitbar clearfix" style="padding-left:85px">
                       
                        <span class="ui-button w150">
                            <span class="button-inner">
                                <span class="button-txt">添加</span>
                                <a href="javascript:;" onclick="return submitForm();"></a>
                            </span>
                        </span>

                        <span class="ui-button w150" style="margin-left:5px">
                            <span class="button-inner">
                                <span class="button-txt">重置</span>
                                <input type="reset" />
                            </span>
                        </span>
                    </div>

                </div>


            </div>

    </form>


    <script type="text/javascript">

        var entity = ${json};
        entity.IsRedirect = (entity.Location||'').length!=0;
        entity.IsSchedule = (entity.ScheduleTime || '').length!=0;
        jr.json.bind('form1', entity);


          //设置是否跳转显示
        var redirectPanel = $jr.$fn('#redirectPanel');
        if(entity.IsRedirect)redirectPanel.removeClass('hidden');
        var redirectFn = function(){
            if(this.attr("checked")){
                if(this.val() == '1'){
                    redirectPanel.removeClass('hidden');
                }else {
                    redirectPanel.addClass('hidden');
                }
            }
        };
        $jr.$fn('#IsRedirect1').change(redirectFn);
        $jr.$fn('#IsRedirect2').change(redirectFn);

        //设置是否定时发布
        var schedulePanel = $jr.$fn('#schedulePanel');
        if(entity.IsSchedule)schedulePanel.removeClass('hidden');
        var schFn = function(){
            if(this.attr("checked")){
                if(this.val() == '1'){  
                    schedulePanel.removeClass('hidden');
                }else {
                    schedulePanel.addClass('hidden');
                }
            }
        };
        $jr.$fn("#IsSchedule1").change(schFn);
        $jr.$fn("#IsSchedule2").change(schFn);
    
        $( ".schedual-time" ).datepicker({
            dateFormat: 'yy-mm-dd',
        });


        jr.$('thumbnail_img').src = entity.Thumbnail;
        var thumbId= 'thumbnail', thumbImg = 'thumbnail_img';
        //上传缩略图
        var thumb_upload = jr.upload({
            id: 'upload_thumbnail',
            debug: !true,
            url: '?module=upload&action=uploadArchiveThumb&upload.id=thumb_upload',
            exts: '*.gif;*.jpg;*.png;*.bmp;*.jpeg'
        },function (result, data) {
            if (result) {
                jr.$(thumbId).value = data.url;
                jr.$(thumbImg).src = data.url;
            } else {
                showErr('上传失败：' + data,2000);
            }
        });

        function getImg() {
            var content = editor.html();
            var reg_html1 = /<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*([^\t\r\n\"'<>]*)/ig;
            //多张图片赋值给下拉框
            var dpimg = document.getElementById('upimg');
            dpimg.innerHTML = '<option>一请选择图片一</option>';
            var match;
            var i = 0;
            while ((match = reg_html1.exec(content)) !== null) {
                var option = document.createElement("OPTION");
                option.innerHTML = "Image" + (++i);
                option.value = match[1];
                dpimg.options.add(option);
            }
            if (dpimg.options.length > 1) {
                dpimg.style.display = '';
            }
            dpimg.onchange = function () {
                var imgurl = this.options[this.selectedIndex].value;
                if (imgurl != "") {
                    $jr.$fn("#" + thumbId).val(imgurl);
                    $jr.$fn("#" + thumbImg).attr("src", imgurl);
                }
            };
        }


        function submitForm() {
            if (jr.validator.validate()) {
                var data = jr.json.toObject('form1');
                data.Content = editor.html();
                if(data.IsRedirect=='0')data.Location='';
		/*
                if (data.Content == '') {
                   showMsg2('请填写内容！');
                    return false;
                }*/
                data["xhr"] = 1;
                jr.xhr.jsonPost('${url}', data, function (json) {
                    if (!json["ErrCode"]) {
                        jr.dialog.alert('文档添加成功',function() {
                            var archiveId = json.Data.ArchiveId;
                            if (menu.edit!=undefined)menu.edit(archiveId);
                            if (_dg) _dg.reload();
                        });
                    } else {
                        jr.dialog.alert(json["ErrMsg"]);
                    }
                });
            }
            return false;
        }

        window.saveData = submitForm;

        jr.$('alias').onblur = function () {
            if (this.nodeName) {
                var ele = this;
                if (!/^[a-zA-Z.*()0-9_-]{0,50}$/.test(this.value)) {
                    jr.validator.setTip(ele, false, 'error');
                } else {
                    jr.validator.removeTip(ele);
                }
            }
        };

        jr.$('alias').nextSibling.onclick = function () {

            var e = this.previousSibling;
            var _title = jr.$fn('#title').val();
            if (_title == '') {
                jr.validator.setTip(e, false, null, '请先填写标题!');
            } else {
                jr.xhr.post('?module=ajax&action=getspellword', 'xhr=1&word=' + encodeURIComponent(_title), function (result) {
                    e.value = result.toLowerCase();
                    e.onblur();
                }, function () {
                    jr.validator.setTip(e, false, null, '获取失败,请重试!');
                });
            }
        };

        $jr.validator.init();

    </script>
</body>
</html>
